/*
题目链接：https://leetcode.cn/problems/minimum-limit-of-balls-in-a-bag/description/
	刘沛民	2024-12-3
*/

class Solution {
public:
    int minimumSize(vector<int>& nums, int maxOperations) {
        auto check = [&](int mid) -> bool {
            int cnt = 0;
            for (auto n: nums) {
                cnt += (n - 1) / mid;
            }
            return cnt <= maxOperations;
        };
        int left = 0, right = *max_element(nums.begin(), nums.end()) + 1;
        while (left + 1 < right) {
            int mid = (left + right) / 2;
            (check(mid) ? right : left) = mid;
        }
        return right;
    }
};
